package br.com.trabalho4.model.shape;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

public class ConvexShape implements Shape {
	private List<Line> edgeList;
	private int points;
	private int zoom;
	
	public ConvexShape(List<Point> pointList) {
		System.out.println(pointList.size());
		this.edgeList = new ArrayList<Line>();
		this.points = pointList.size();
		this.zoom = 1;
		
		initialize(pointList);
	}
	
	private void initialize(List<Point> pointList) {
		int i = 1;
		for (Point p : pointList) {
			if (i < pointList.size()) {
				edgeList.add(new Line(p, pointList.get(i)));
			} else {
				edgeList.add(new Line(p, pointList.get(0)));
			}
			
			i++;
		}
	}
	
	@Override
	public void draw(Graphics g) {
		Graphics gg = g.create();
		
//		wireframe
//		for (Line l : edgeList) {
//			l.setZoom(zoom);
//			l.draw(gg);
//		}
		
//		solid
//		for (Line l : edgeList) {
//			l.setZoom(zoom);
//		}
		
		for (int i = 0; i < points - 1; i++) {
			new Line(edgeList.get(0).getBegin(), edgeList.get(i).getEnd(), zoom).draw(gg, edgeList.get(i+1).getEnd());
		}
		//edgeList.get(0).draw(gg, edgeList.get(1).getEnd());
		
		
//		if (edgeList.get(0).getBegin().equals(edgeList.get(1).getBegin())) {
//			edgeList.get(0).draw(gg, edgeList.get(1).getEnd());
//		} else {
//			
//			System.out.println(edgeList.get(0).getBegin().getX()+" "+edgeList.get(0).getBegin().getY()+" "+edgeList.get(0).getEnd().getX()+" "+edgeList.get(0).getEnd().getY());
//			System.out.println(edgeList.get(1).getBegin().getX()+" "+edgeList.get(1).getBegin().getY());
//			edgeList.get(0).draw(gg, edgeList.get(1).getBegin());
//		}
		
		gg.dispose();
		
	}
	
	@Override
	public void setZoom(int zoom) {
		this.zoom = zoom;
	}
}
